package org.example.product.service.impl;
import org.example.product.entity.ResultBody;
import org.example.product.mapper.OrderMapper;
import org.example.product.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceimpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public ResultBody addOrder(String OrderCode, String userphone, String Goods_code, double total_amount, String Goods_name, String buyphone) {
        if(orderMapper.addOrder(OrderCode, userphone, Goods_code, total_amount, Goods_name,buyphone)>0&&orderMapper.updateStatus(Goods_code,"售罄")>0)
        {
            return new ResultBody (200,"添加订单成功",true);
        }
        else
            return new ResultBody(400,"添加订单失败",false);
    }
    @Override
    public ResultBody displayOrderU(String user_phone)
    {
        if(orderMapper.displayOrderU(user_phone)!=null)
            return new ResultBody(200,"显示本人订单成功",orderMapper.displayOrderU(user_phone),orderMapper.displayOrderU(user_phone).size());
        else
            return new ResultBody(400,"显示本人订单失败",false);
    }
    @Override
    public ResultBody displayOrderB(String Buyers_phone)
    {
        if(orderMapper.displayOrderU(Buyers_phone)!=null)
            return new ResultBody(200,"卖出订单显示成功",orderMapper.displayOrderB(Buyers_phone),orderMapper.displayOrderB(Buyers_phone).size());
        else
            return new ResultBody(400,"显示本人订单失败",false);
    }

}
